home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / fspsh < prev    next >
Encoding:
Text File  |  1994-07-16  |  9.3 KB  |  254 lines

  1. #!/bin/sh -f
  2. # bash in fact. Linux' bash. I don't have bourne shell! :( Should be ok tho.
  3. # My bourne shell scripting skills are pretty reduced. Lot to improve there.
  4. # I prefer using the separate commands but some people don't like it.
  5. # This is FSP Sh , the Shell Script FSP command interpreter by MegaFork, 1.01
  6. # WHAT TO DO ?!?!
  7. # ---------------
  8. # For quick start, just put the absolute path of your fsp271mf binaries in
  9. # FSP_PATH=/usr/local/bin
  10. # then run fspsh, try a few things. Improve my script. mail me your version ;)
  11. #
  12. # fsp-client and FSPSh : some pros and some cons ...
  13. # It's of course ridiculously rudimentary compared to the fsp-client. 
  14. # It obviously doesn't like VMS. So do I. No support for VMS ;)
  15. # I have some problems with parsing. Especially with the -f flag.Can't change.
  16. # But it works with my hacked FSP ;) and it should be smaller than having both
  17. # the separate commands and the fspclient. Another good thing is you can 
  18. # compress it (alias fsp sh \`compress\<fspsh.Z\`) without having to wait too
  19. # much on start. Its portability should be better than fsp-client's, since a
  20. # side effect of my little scripting-knowledge is that I use a very reduced set
  21. # of commands ;) .
  22. # It's alot more hackable. If it ever becomes popular, it should be improved 
  23. # much more faster ...
  24. # It's `ready-for-use'. No Makefile tweaking. 
  25. #
  26. # Please tell me what you have improved in it, I'm sure you did.
  27. # FspSh's specific commands.
  28. # motd: the root dir's .README.
  29. # echo <string>: just performs an 'echo' ( Useful for macros ... )
  30. # prompt: change the prompt... Warning: I parse prompts: special shell chars
  31. #       should be quoted twice... but this allow envs to be parsed.
  32. #        example: prompt $FSP_HOST:$FSP_PORT:$FSP_DIR\\> ( yeah, tricky )
  33. # bat: start logging action in a shell script.
  34. # enbat: end logging actions.
  35. # batfile <file>: set shell script filename.
  36. # run <file>: run a *batch* file.
  37. #  (note: if you want a rc, just make a bat, and put the filename at FSPSH_RC=)
  38. # macro: start a macro.
  39. # endmacro: end recording.
  40. # log <file>: set logfile.( where the macros will be appent. Remove if you 
  41. #                wish to make a new file )
  42. #
  43. # coreleft: prints out the space left in kbytes (only on FSP servers that run
  44. #         hacked version and have that option enabled)
  45. #
  46. # How to Run a Previously recored macro?
  47. # just fspsh < <logfilename> or fspsh <logfilename>
  48. # the second form is highly recommended over the first one.
  49. # Note that incomplete name will cause fspsh to look in the current dir for
  50. # the filename, and if not found in $FSP_PATH/filename. Macros that don't end
  51. # with a `quit' are corrected.
  52. # WARNING: macro doesn't destroy your old file. It appends to it.
  53. # WARNING: bat doesn't append to file. It starts a new one.
  54. # this `quick help' is taking too much. I'll make a separate info file I guess.
  55.  
  56. #function args { echo $ |cut -d' ' -f2- }
  57.  
  58. # Default Host.
  59. FSP_PORT=6999
  60. FSP_HOST=localhost
  61. FSP_DELAY=3000
  62. FSP_TRACE=
  63. FSP_DIR=/
  64.  
  65. # Where your FSP clients reside. Absolute path.  
  66. FSP_PATH=/usr/local/bin
  67. FSPSH_PROMPT='fsp\> '
  68. #FSPSH_PROMPT="\$FSP_HOST:\$FSP_PORT:\$FSP_DIR\>"
  69. RECORD_FILE=$FSP_PATH/macros
  70. BATCH_FILE=/batch
  71. BATCH_PATH=`pwd`
  72. FSPSH_RC=
  73.  
  74. # You shouldn't have to edit below this line unless you're improving the script.
  75.  
  76. BATCHING=OFF
  77. IS_RECORDING=NO
  78. export FSP_PATH
  79. source $FSPSH_RC
  80. if [ $1x != x ]
  81. then
  82.   echo Running Macro $1.
  83.   MACRONAME=$1
  84.   if [ `basename $1` = $1 ] ; then
  85.     if [ ! -f $1 ] ; then 
  86.         echo Correcting $1 to $FSP_PATH/$1 
  87.         MACRONAME=$FSP_PATH/$1    
  88.     fi
  89.   fi
  90.   if [ "`tail -1 $MACRONAME`" != quit ] ;then
  91.     echo quit >> $MACRONAME # if it was `exit' then oh well it'll have two.
  92.   fi
  93.   fspsh < $MACRONAME
  94.   exit 0
  95. fi
  96.  
  97.   export FSP_HOST
  98.   export FSP_PORT
  99.   export FSP_DELAY
  100.   export FSP_TRACE
  101.   export FSP_DIR
  102.   export FSP_PASSWORD
  103.   export IS_RECORDING
  104.   export RECORD_FILE
  105.  
  106. while [ 1 ]
  107. do
  108.   #echo -n 'fsp> '
  109.   echo -n "`eval echo $FSPSH_PROMPT` "
  110.   read line
  111.   if [ $IS_RECORDING = YES ] 
  112.   then
  113.     echo "$line" >>$RECORD_FILE
  114.   fi
  115.   cmd=`echo $line|cut -d' ' -f1`
  116.   export SHCMD=
  117.   case $cmd in
  118.     quit|exit) echo Goodbye.;SHCMD="exit 0";;
  119.     ver*) echo Shell Script FSP Interpreter 1.01 by Patrick Nguyen -  MegaFork
  120.          #$FSP_PATH/fver x # local ver displayed when fver is given an arg.
  121.          #$FSP_PATH/fver # server ver displayed when fver is given no args.
  122.          SHCMD='$FSP_PATH/fver x;$FSP_PATH/fver'
  123.          SHCMD="eval $SHCMD"
  124.          ;;
  125.     help) if [ `echo $line|wc -w` != 2 ] ;then
  126.          echo Shell Script FSP Interpreter by Patrick Nguyen - MegaFork 
  127.          echo Available commands \(Unsorted\):
  128.          echo "motd      open    close     port    pass    trace    delay"
  129.          echo "dir       cd      put       get     ldir    lpwd     lcd"
  130.          echo "rmdir     mkdir   show      du      pwd     grab     pro"
  131.          echo "find      ls      shell     ver     quit    del      macro"
  132.          echo "endmacro  logfile echo      prompt  !       bat      batfile"
  133.          echo "endbat    run     coreleft  touch"
  134.          echo typing help \<cmd\> should \(hopefully\) print out a quick help.
  135.       else echo You have tried ${line}. I\'ll make quick online docs available
  136.            echo as soon as I figure out how to do imbricated case ...But now
  137.            echo I guess i\'ll go to sleep.
  138.       fi;;
  139.     echo) SHCMD="$line";;
  140.     motd) SHCMD="$FSP_PATH/fprocmd /";;
  141.     prompt) SHCMD="export FSPSH_PROMPT=`echo $line|cut -d' ' -f2-` ";;
  142.     coreleft) # Only on server that use fsp.271mf with the quota option enabled.
  143.           if [ `$FSP_PATH/flscmd -1 /|grep FSP_LEFT`x != x ] ;then
  144.         # I'll make a better one when I'll have time
  145.           SHCMD='eval echo There is \`echo `$FSP_PATH/fcatcmd /FSP_LEFT|head -1`/1000\|bc\` kb left' 
  146.         SHCMD="`eval echo $SHCMD`"
  147.           else 
  148.         SHCMD="echo No quota here."
  149.           fi
  150.       ;;
  151.     open|o) 
  152.       SHCMD="export FSP_HOST=`echo $line|cut -d' ' -f2`"
  153.       FSP_HOST=`echo $line|cut -d' ' -f2`
  154.       if [ `echo $line|wc -w` != 2 ] ;then
  155.         SHCMD="$SHCMD\;FSP_PORT=`echo $line|cut -d' ' -f3`"
  156.         FSP_PORT=`echo $line|cut -d' ' -f3`
  157.       fi
  158.           echo Setting Host: $FSP_HOST : $FSP_PORT
  159.           ;;
  160.     close) 
  161.       echo Don\'t need to \`close\', since there\'s no connection.;;
  162.     port) SHCMD="export FSP_PORT=`echo $line|cut -d' ' -f2`"
  163.       echo Setting Port: `echo $line|cut -d' ' -f2` \(Host is $FSP_HOST\)
  164.       ;;
  165.     pass) SHCMD="export FSP_PASSWORD=`echo $line|cut -d' ' -f2`";echo Ok.;;
  166.     trace) SHCMD="export FSP_TRACE=`echo $line|cut -d' ' -f2`" 
  167.        echo TRACE value is now: `echo $line|cut -d' ' -f2`.;;
  168.     delay) SHCMD="export FSP_DELAY=`echo $line|cut -d' ' -f2`"
  169.        echo Delay: `echo $line|cut -d' ' -f2`;;
  170.     dir) if [ `echo $line|wc -w` != 1 ]
  171.           then
  172.         ARGS=`echo $line|cut -d' ' -f2-`
  173.           else ARGS=
  174.      fi
  175.          SHCMD="$FSP_PATH/flscmd -lA $ARGS";;
  176.     cd) if [ `echo $line|wc -w` != 1 ] ;then
  177.         ARGS=`echo $line|cut -d' ' -f2-` ; else ARGS=
  178.     fi
  179.     SHCMD="export FSP_DIR=`$FSP_PATH/fcdcmd $ARGS`";;
  180.     #put|get)
  181.     put) SHCMD="$FSP_PATH/fput `echo $line|cut -d' ' -f2-`" ;;
  182.     get) SHCMD="$FSP_PATH/fgetcmd `echo $line|cut -d' ' -f2-`" ;;
  183.     ldir) if [ `echo $line|wc -w` != 1 ] ;then
  184.         ARGS=`echo $line|cut -d' ' -f2-`
  185.              else ARGS=
  186.       fi
  187.       SHCMD="ls -lA $ARGS" ;;
  188.     lcd) SHCMD="cd `echo $line|cut -d' ' -f2`" ;;
  189.     lpwd) echo cwd is now: `pwd`;;
  190.     #mkdir|rmdir) Goddam ppl who wrote fsp don't like to be coherent do they.
  191.     rmdir) SHCMD="$FSP_PATH/f${cmd}cmd `echo $line|cut -d' ' -f2`"
  192.         ;;
  193.     mkdir) SHCMD="$FSP_PATH/f$line" ;;
  194.     cat|show) SHCMD="$FSP_PATH/fcatcmd `echo $line|cut -d' ' -f2-`" ;;
  195.     del|rm) SHCMD="$FSP_PATH/frmcmd `echo $line|cut -d' ' -f2-`" ;;
  196.     du) if [ `echo $line|wc -w` != 1 ] ;then ARGS=`echo $line|cut -d' ' -f2-`
  197.     else ARGS= ;fi
  198.     SHCMD="$FSP_PATH/fducmd $ARGS" ;;
  199.     pwd) echo $FSP_DIR on $FSP_HOST port $FSP_PORT ;;
  200.     grab|pro|find|ls)
  201.     if [ `echo $line|wc -w` != 1 ] ;then
  202.       ARGS=`echo $line|cut -d' ' -f2-`
  203.         else ARGS=
  204.     fi
  205.     SHCMD="$FSP_PATH/f${cmd}cmd $ARGS"
  206.         ;;
  207.     touch) FILE=`echo $line|cut -d' ' -f2`
  208.        SHCMD='touch $FILE;$FSP_PATH/fput $FILE;rm -f $FILE'
  209.            SHCMD="eval $SHCMD"
  210.        ;;
  211.     shell) /bin/sh -i;;
  212.     log) RECORD_FILE=`echo $line|cut -d' ' -f2` 
  213.      echo Setting logfile value to $RECORD_FILE .
  214.          ;;
  215.     macro) echo Starting Record. \( $RECORD_FILE \)  
  216.        IS_RECORDING=YES ;;
  217.     endmacro) echo Stopping Record. \( $RECORD_FILE \) ; IS_RECORDING=NO ;;
  218.     bat) echo Starting BATCH record. \( $BATCH_PATH/$BATCH_FILE \).
  219.      echo "#!/bin/sh" >$BATCH_PATH/$BATCH_FILE
  220.      export BATCHING=ON ;;
  221.     endbat) echo Ending BATCH recording. \( $BATCH_PATH/$BATCH_FILE \).
  222.         export BATCHING=OFF ;;
  223.     batfile) if [ `echo $line|wc -w` != 2 ] ;then
  224.         echo Current BATH file\'s value is $BATCH_PATH/$BATCH_FILE .
  225.          else 
  226.         BATCH_FILE=`echo $line|cut -d' ' -f2` 
  227.          if [ `basename $BATCH_FILE` != $BATCH_FILE ]
  228.             then
  229.            BATCH_PATH=`echo $BATCH_FILE | sed -e 's;/[a-zA-Z0-9]*$;;'`
  230.            BATCH_FILE=`basename $BATCH_FILE`
  231.         fi
  232.         echo Setting BATCH file\'s value to $BATCH_PATH/$BATCH_FILE .
  233.          fi
  234.          ;;
  235.     run|source) SHCMD="source `echo $line|cut -d' ' -f2-`" ;;
  236.     \!) /bin/sh -c "`echo $line|cut -d' ' -f2-`" ;;
  237.     *) if [ ${line}x != x ] ;then 
  238.           echo Unknown Command: $cmd
  239.        fi;;
  240.   esac
  241.   if [ "${SHCMD}"x != x ] ;then
  242.     if [ $BATCHING = ON ] ;then
  243.        echo "$SHCMD">>$BATCH_PATH/$BATCH_FILE
  244.     fi
  245.     $SHCMD
  246.   fi
  247.   export FSP_HOST
  248.   export FSP_PORT
  249.   export FSP_DIR
  250.   export FSP_TRACE
  251.   export FSP_DELAY
  252.   export FSP_PASSWORD
  253. done
  254.